package cn.lil.servlet;

import cn.lil.dao.OrderDao;
import cn.lil.model.Order;
import cn.lil.service.OrderService;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "OrderUpdateStatusServlet", value = "/OrderUpdateStatusServlet")
public class OrderUpdateStatusServlet extends HttpServlet {
    OrderService orderService = new OrderService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int orderId = ((Order) request.getSession().getAttribute("order")).getId();
        try {
            orderService.updateStatus(orderId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("MySubmitOrderServlet").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int orderId = ((Order) request.getSession().getAttribute("order")).getId();
        try {
            orderService.updateStatus(orderId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("MySubmitOrderServlet").forward(request, response);
    }
}
